//	ID : pallab81
// 	PROG : 624
// 	LANG : C++
// 	2011-07-19-17.48.14 Tuesday
//
// 	"I have not failed, I have just found 10000 ways that won't work.
//


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>

using namespace std;

#define fo(i,ed) for(int i = 0 ; i < ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )

int T;
int N;
vector< int > w;
vector< vector<int> >  dp,p;
inline void read() {
    scanf("%d",&N);
    w.assign(N+10,0);
    int i;
    for(i=1;i<=N;++i){
        scanf("%d",&w[i]);
    }
}
inline void back_track(int now_iteam, int now_value) {
    if(now_iteam==0) {
        return ;
    }
    if( p[now_iteam][ now_value] !=-1 ) {
        back_track(now_iteam-1,now_value- w[now_iteam]);
        printf("%d ",w[now_iteam]);
    } else {
        back_track(now_iteam-1,now_value);
    }
}
inline void proc() {
    int i,j;
    dp.assign(2, vector<int>(T+10,-1) );
    p.assign(N+10, vector< int > (T+10,-1) );

    for(i=1; i<=N; ++i) {
        dp[0][0]=0;
        for(j=0; j<=T; ++j) {
            if( j>=w[i] && dp[0][j-w[i]]!=-1 ) {
                dp[1][j]=0;
                p[i][j]=1;
            } else {
                dp[1][j]=dp[0][j];
            }
        }
        swap(dp[0],dp[1]);
    }
    int _T = T;
    while( dp[0][_T]!=0 ) {
        --_T;
    }
    back_track(N,_T);
    printf("sum:%d\n",_T);
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt","rt",stdin);
#endif
    while( scanf("%d",&T)==1 ) {
        read();
        proc();
    }

    return 0;
}


